<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/1999/REC-html401-19991224/strict.dtd">
<html>
<head>
<META http-equiv=Content-Type content="text/html; charset=UTF-8">
<title>Exported from Notepad++</title>
<style type="text/css">
span {
	font-family: 'Courier New';
	font-size: 10pt;
	color: #000000;
}
.sc0 {
}
.sc1 {
	font-style: italic;
	color: #0000FF;
}
.sc2 {
	font-style: italic;
	color: #0000FF;
}
.sc5 {
	font-weight: bold;
	font-style: italic;
	color: #0000FF;
}
.sc6 {
	font-weight: bold;
	color: #008000;
}
.sc8 {
	font-weight: bold;
	font-style: italic;
	color: #008000;
}
.sc10 {
	font-weight: bold;
	color: #0080FF;
}
.sc11 {
}
.sc14 {
	color: #8080FF;
}
</style>
</head>
<body>
<div style="float: left; white-space: pre; line-height: 1; background: #FFFFFF; "><span class="sc2">// ===================================================== //</span><span class="sc0">
</span><span class="sc2">// === MODULE SUBSTITUANT &amp; TEST UNITAIRE POUR ALICE === //</span><span class="sc0">
</span><span class="sc2">// ===================================================== //</span><span class="sc0">

</span><span class="sc1">/* 
    alice est chargee du xor(a, b).
    En attendant d'avoir un circuit operationnel,
    elle definit une application externe (pipe).
    
    Cette application peut etre ecrite facilement en bebop-hdl, 
    en utilisant les fichiers bpo basés sur ocaml
*/</span><span class="sc0">

</span><span class="sc10">#</span><span class="sc5">source</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc14">"ocaml"</span><span class="sc0">

</span><span class="sc10">#</span><span class="sc6">init</span><span class="sc0"> </span><span class="sc10">%{</span><span class="sc0">
    </span><span class="sc10">(</span><span class="sc11">*</span><span class="sc0"> </span><span class="sc11">ceci</span><span class="sc0"> </span><span class="sc11">est</span><span class="sc0"> </span><span class="sc11">la</span><span class="sc0"> </span><span class="sc11">fonction</span><span class="sc0"> </span><span class="sc11">correspondant</span><span class="sc0"> </span><span class="sc11">au</span><span class="sc0"> </span><span class="sc11">circuit</span><span class="sc0"> </span><span class="sc11">d'alice</span><span class="sc0"> </span><span class="sc11">*</span><span class="sc10">)</span><span class="sc0">
    </span><span class="sc11">let</span><span class="sc0"> </span><span class="sc11">alice_fct</span><span class="sc0"> </span><span class="sc11">a</span><span class="sc0"> </span><span class="sc11">b</span><span class="sc0"> </span><span class="sc11">s</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc11">s</span><span class="sc0"> </span><span class="sc10">:=</span><span class="sc0"> </span><span class="sc11">a</span><span class="sc0"> </span><span class="sc10">&lt;&gt;</span><span class="sc0"> </span><span class="sc11">b</span><span class="sc10">;;</span><span class="sc0">
</span><span class="sc10">}%</span><span class="sc0">

</span><span class="sc2">// On définit une méthode de test unitaire</span><span class="sc0">
</span><span class="sc10">#</span><span class="sc6">method</span><span class="sc0"> </span><span class="sc6">test</span><span class="sc0"> </span><span class="sc10">(</span><span class="sc11">a</span><span class="sc10">,</span><span class="sc0"> </span><span class="sc11">b</span><span class="sc10">,</span><span class="sc0"> </span><span class="sc11">s</span><span class="sc10">)</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc10">()</span><span class="sc0">
</span><span class="sc10">#</span><span class="sc5">with</span><span class="sc0"> </span><span class="sc5">code</span><span class="sc0"> </span><span class="sc10">%{</span><span class="sc0">
    </span><span class="sc10">(</span><span class="sc11">*</span><span class="sc0"> </span><span class="sc11">ceci</span><span class="sc0"> </span><span class="sc11">est</span><span class="sc0"> </span><span class="sc11">du</span><span class="sc0"> </span><span class="sc5">code</span><span class="sc0"> </span><span class="sc11">ocaml</span><span class="sc10">,</span><span class="sc0"> </span><span class="sc11">doit</span><span class="sc0"> </span><span class="sc11">etre</span><span class="sc0"> </span><span class="sc11">de</span><span class="sc0"> </span><span class="sc11">type</span><span class="sc0"> </span><span class="sc11">unit</span><span class="sc0"> </span><span class="sc11">*</span><span class="sc10">)</span><span class="sc0">
    </span><span class="sc10">(</span><span class="sc11">*</span><span class="sc0"> </span><span class="sc11">et</span><span class="sc0"> </span><span class="sc11">peut</span><span class="sc0"> </span><span class="sc11">declancher</span><span class="sc0"> </span><span class="sc11">l'exception</span><span class="sc0"> </span><span class="sc8">TEST_FAILURE</span><span class="sc0"> </span><span class="sc11">*</span><span class="sc10">)</span><span class="sc0">
    </span><span class="sc11">let</span><span class="sc0"> </span><span class="sc11">s_expected</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc11">ref</span><span class="sc0"> </span><span class="sc11">false</span><span class="sc0"> </span><span class="sc11">in</span><span class="sc0">
    </span><span class="sc11">alice_fct</span><span class="sc0"> </span><span class="sc11">a</span><span class="sc0"> </span><span class="sc11">b</span><span class="sc0"> </span><span class="sc11">s_expected</span><span class="sc10">;</span><span class="sc0">
    </span><span class="sc5">if</span><span class="sc0"> </span><span class="sc11">s</span><span class="sc0"> </span><span class="sc10">&lt;&gt;</span><span class="sc0"> </span><span class="sc11">!s_expected</span><span class="sc0">
    </span><span class="sc5">then</span><span class="sc0"> </span><span class="sc11">raise</span><span class="sc0"> </span><span class="sc10">(</span><span class="sc8">TEST_FAILURE</span><span class="sc0"> </span><span class="sc10">(</span><span class="sc11">true</span><span class="sc10">,</span><span class="sc0"> </span><span class="sc14">"ALICE !!"</span><span class="sc10">))</span><span class="sc0">
    </span><span class="sc5">else</span><span class="sc0"> </span><span class="sc10">()</span><span class="sc0"> 
</span><span class="sc10">}%</span><span class="sc0">

</span><span class="sc2">// La méthode main est le substituant</span><span class="sc0">
</span><span class="sc10">#</span><span class="sc11">main</span><span class="sc0"> </span><span class="sc10">(</span><span class="sc11">a</span><span class="sc10">,</span><span class="sc0"> </span><span class="sc11">b</span><span class="sc10">)</span><span class="sc0"> </span><span class="sc10">=</span><span class="sc0"> </span><span class="sc11">s</span><span class="sc0">
</span><span class="sc10">#</span><span class="sc5">with</span><span class="sc0"> </span><span class="sc5">code</span><span class="sc0"> </span><span class="sc10">%{</span><span class="sc0">
    </span><span class="sc10">(</span><span class="sc11">*</span><span class="sc0"> </span><span class="sc8">Ceci</span><span class="sc0"> </span><span class="sc11">est</span><span class="sc0"> </span><span class="sc11">du</span><span class="sc0"> </span><span class="sc5">code</span><span class="sc0"> </span><span class="sc11">ocaml</span><span class="sc0"> </span><span class="sc11">indiquant</span><span class="sc0"> </span><span class="sc11">le</span><span class="sc0"> </span><span class="sc11">calcul</span><span class="sc0"> </span><span class="sc11">de</span><span class="sc0"> </span><span class="sc11">s</span><span class="sc0"> </span><span class="sc11">*</span><span class="sc10">)</span><span class="sc0">
    </span><span class="sc10">(</span><span class="sc11">*</span><span class="sc0"> </span><span class="sc11">a</span><span class="sc0"> </span><span class="sc11">et</span><span class="sc0"> </span><span class="sc11">b</span><span class="sc0"> </span><span class="sc11">sont</span><span class="sc0"> </span><span class="sc11">dans</span><span class="sc0"> </span><span class="sc11">les</span><span class="sc0"> </span><span class="sc11">entrées</span><span class="sc0"> </span><span class="sc11">donc</span><span class="sc0"> </span><span class="sc11">de</span><span class="sc0"> </span><span class="sc11">type</span><span class="sc0"> </span><span class="sc11">bool</span><span class="sc0"> </span><span class="sc11">*</span><span class="sc10">)</span><span class="sc0">
    </span><span class="sc10">(</span><span class="sc11">*</span><span class="sc0"> </span><span class="sc11">s</span><span class="sc0"> </span><span class="sc11">est</span><span class="sc0"> </span><span class="sc11">une</span><span class="sc0"> </span><span class="sc11">sortie</span><span class="sc10">,</span><span class="sc0"> </span><span class="sc11">donc</span><span class="sc0"> </span><span class="sc11">de</span><span class="sc0"> </span><span class="sc11">type</span><span class="sc0"> </span><span class="sc11">bool</span><span class="sc0"> </span><span class="sc11">ref</span><span class="sc0"> </span><span class="sc11">*</span><span class="sc10">)</span><span class="sc0">
    </span><span class="sc11">alice_fct</span><span class="sc0"> </span><span class="sc11">a</span><span class="sc0"> </span><span class="sc11">b</span><span class="sc0"> </span><span class="sc11">s</span><span class="sc0">
</span><span class="sc10">}%</span><span class="sc0">
</span></div></body>
</html>
